package com.yiban.demo.Global.Configuration;

import com.yiban.demo.Access.Service.AccessService;
import com.yiban.demo.Global.ServletComponent.UriControlFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Configuration;

/**
 * 用于统一注入过滤器
 */
@Configuration
public class FilterConfig {
    //todo 正式上线后记得去掉注释，这里注释掉@Bean是为了方便测试
//    @Bean
    public FilterRegistrationBean<UriControlFilter> uriControlFilter(AccessService accessService){
        final FilterRegistrationBean<UriControlFilter> uriFilterBean = new FilterRegistrationBean<>();
        uriFilterBean.setFilter(new UriControlFilter(accessService));
        uriFilterBean.addUrlPatterns("/*");
        uriFilterBean.setOrder(0);
        uriFilterBean.setName("uriControllerFilter");
        uriFilterBean.setEnabled(true);
        return uriFilterBean;
    }

}
